<template>
  <view>
    <web-view :src="src"></web-view>
  </view>
</template>
<script setup>
import { onLoad, onShareAppMessage, onShow } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { QRCODE_BASE_URI } from "./config";
import { ObjectToQueryString } from "@/utils/utils";
import { ShareConfig } from "./config";

const src = ref("");
const locationInfo = reactive({ latitude: "", longitude: "" })

onShareAppMessage(() => ShareConfig())

onLoad((options) => {
  getApp().accessLogAdd();
  uni.getLocation({
    type: "gcj02",
    success: (result) => {
      Object.assign(locationInfo, result)
    },
    async complete() {
      await getApp().getUserLoginInfo()
      const source = options.source ? "record" : "index";
      const queryPrams = ObjectToQueryString({
        source,
        accesstoken: uni.getStorageSync("TOKEN"),
        code: options.code || "",
        'openid': uni.getStorageSync("OPENID"),
        'unionid': uni.getStorageSync("UNIONID"),
        'memberid': getApp().globalData?.user?.memberScore?.memberId || '',
        agree: uni.getStorageSync('CLOUD_SAMPLE_AGREE1') || false,
        latitude: locationInfo.latitude,
        longitude: locationInfo.longitude,
        birthday: getApp().globalData.user.birthday
      })
      src.value = `${QRCODE_BASE_URI}/b/index.html?${queryPrams}`
    },
  });
  // 是否登录注册
  if (!getApp().globalData.user.phone) {
    uni.navigateTo({ url: "/pages/vip/register?tag=scanCode" });
  }
})
</script>

<style></style>
